<template>
  <el-form ref="searchForm" :model="form" :rules="rules" label-width="120px" >
    <el-form-item :label="`${$t('ToolingChecklist')}`" prop="formId">
      <el-select v-model="form.formId">
        <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id"/>
      </el-select>
    </el-form-item>
    <el-form-item :label="`${$t('toolingBarcode')}`" prop="toolingBarcode">
      <el-input v-model="form.toolingBarcode" clearable/>
    </el-form-item>
    <el-row>
      <el-col :span="24" :offset="19">
        <el-button
          icon="el-icon-document-add"

          type="primary"
          @click="getEqpForm('searchForm')"
        >{{ $t('GenerateChecklist') }}</el-button
        >
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import networkTips from '@/mixins/networkTips'
import eFormCheckApi from '@/api/eForm/eFormCheck'
import toolingBaseApi from '@/api/Tooling/toolingBasicInfo'
export default {
  name: 'SearchForm',
  components: {},
  mixins: [networkTips],
  props: {
    form: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      rules: {
        formId: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
        toolingBarcode: [{ required: true, message: '请填写备件编号', trigger: 'blur' }]
      },
      typeList: []
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getFormTypeList()
  },
  mounted() {},
  methods: {
    // 获取检查表数据
    async getFormTypeList() {
      const res = await eFormCheckApi.getFormList({ category: 4 })
      this.typeList = res.data
    },
    getEqpForm(formName) {
      this.$refs[formName].validate(async(valid) => {
        if (valid) {
          const res = await toolingBaseApi.getToolingForm(this.form)
          if (res.code === 1) {
            // const { toolingType, toolingModel } = res.data
            // this.form.toolingType = toolingType
            // this.form.toolingModel = toolingModel
            const tempForm = Object.assign({}, this.form, res.data)
            this.$emit('getEqpForm', { form: tempForm })
          }
          this.netTips(res)
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .el-form-item__content div {
    width: 40%;
  }
</style>
